﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace THenu.TinyHourseLib.DesignPattern.Behavioral_Patterns.State_Pattern
{
    class StatePattern : IPatternDemonstrate
    {
        public void StructuralCode()
        {
            // Setup context in a state
            Context c = new Context(new ConcreteStateA());

            // Issue requests, which toggles state
            c.Request();
            c.Request();
            c.Request();
            c.Request();
        }

        public string PatternDescription()
        {
            string description = @"
Definition
Allow an object to alter its behavior when its internal state changes. The object will appear to change its class.

Participants

    The classes and objects participating in this pattern are:

Context  (Account)
defines the interface of interest to clients
maintains an instance of a ConcreteState subclass that defines the current state.
State  (State)
defines an interface for encapsulating the behavior associated with a particular state of the Context.
Concrete State  (RedState, SilverState, GoldState)
each subclass implements a behavior associated with a state of Context";
            return description;
        }

        public void RealWorldExample()
        {
            // Open a new account
           RealWorld.Account account = new  RealWorld.Account("Jim Johnson");

            // Apply financial transactions
            account.Deposit(500.0);
            account.Deposit(300.0);
            account.Deposit(550.0);
            account.PayInterest();
            account.Withdraw(2000.00);
            account.Withdraw(1100.00);
        }
    }
}
